const re = function (e, t) {
  var n = {
    row: e.row,
    col: e.col
  }
  var o = {
    row: e.row,
    col: e.col
  }
  var r = t.getCellMeta(e.row, e.col);
  return e.hasOwnProperty("className") && (n.className = e.className,
    o.className = r.className),
    e.style && (n.style = e.style,
      o.style = Object.assign({}, r.style)),
    e.border && (n.border = JSON.parse(JSON.stringify(e.border || {})),
      o.border = JSON.parse(JSON.stringify(r.border || {}))),
  {
    updateCellMeta: n,
    presentCellMeta: o
  }
}
const J = function (e) {
  if (Array.isArray(e)) {
    for (var t = 0, n = Array(e.length); t < e.length; t++)
      n[t] = e[t] || null;
    return n
  }
  return Array.from(e)
}
export class Z {
  constructor(t, n) {
    this.cellMetas = t;
    this.hotInstance = n;
    this.diffObject = {};
  }

  diff() {
    if (this.cellMetas && Array.isArray(this.cellMetas) && this.cellMetas.length > 0) {
      var t = []
        , n = [];
      this.cellMetas.forEach((o) => {
        var r = re(o, this.hotInstance)
          , i = r.updateCellMeta
          , a = r.presentCellMeta;
        t = t.concat(i),
          n = n.concat(a)
      })

      this.diffObject = {
        updatedCellMetas: t,
        presentCellMetas: n
      }
    }
    return this
  }
  applyChange() {
    var t = this;
    return this.diffObject.updatedCellMetas && Array.isArray(this.diffObject.updatedCellMetas) && this.diffObject.updatedCellMetas.length > 0 && this.diffObject.updatedCellMetas.forEach(function (e) {
      t.hotInstance.setCellMetaObject(e.row, e.col, e)
    }),
      this
  }
  revertChange(e) {
    var t = this;
    return this.diffObject.presentCellMetas && Array.isArray(this.diffObject.presentCellMetas) && this.diffObject.presentCellMetas.length > 0 && this.diffObject.presentCellMetas.forEach(function (e) {
      t.hotInstance.setCellMetaObject(e.row, e.col, e)
    }),
      this
  }
}

export class ee {

  constructor(t, n) {
    this.mergeCells = t
    this.hotInstance = n
    this.diffObject = {}
  }

  diff() {
    this.diffObject.updatedMergeCells = this.mergeCells
    this.diffObject.presentMergeCells = JSON.parse(JSON.stringify(this.hotInstance.getSettings().mergeCells || []))
    return this
  }
  applyChange(e) {
    return this.hotInstance.updateSettings({
      mergeCells: this.diffObject.updatedMergeCells
    }),
      this
  }
  revertChange() {
    return this.hotInstance.updateSettings({
      mergeCells: this.diffObject.presentMergeCells
    }),
      this
  }
}

export class te {
  constructor(t, n) {
    this.cellDatas = t
    this.hotInstance = n
    this.diffObject = {}
  }

  diff() {
    {
      var e = this
        , t = this.hotInstance.getSettings()
        , n = t.cellWithField
        , o = t.filters
        , r = t.expressions
        , i = []
        , a = Object.assign({}, n)
        , s = []
        , l = o
        , u = t.cellWithImg
        , c = Object.assign({}, u);
      var cellWithQRcode = t.cellWithQRcode
      var copyQr = Object.assign({}, cellWithQRcode)
      var cellWithBRcode = t.cellWithBRcode
      var copyBr = Object.assign({}, cellWithBRcode)
      return this.cellDatas && Array.isArray(this.cellDatas) && this.cellDatas.length > 0 && this.cellDatas.forEach(function (t) {
        var n = t[0]
          , u = t[1]
          , d = t[2];
        if (null === d) {
          delete a[n + ":" + u];
          delete c[n + ":" + u];
          delete copyQr[n + ":" + u];
          delete copyBr[n + ":" + u];
          var h = Object.values(a) && Object.values(a).map(function (e) {
            return e && e.RootMetaDataID
          });
          l = o.filter(function (e) {
            return h.indexOf(e.metaDataID) > -1
          })
        }
        if ("[object Object]" === Object.prototype.toString.call(d) && d.hasOwnProperty("Expression")) {
          a[n + ":" + u] = {
            Expression: d.Expression,
            FormatConfig: d.FormatConfig || null,
            Format: d.Format,
            RootMetaDataID: d.RootMetaDataID,
            IsDigSign: !!d.SignType || d.IsDigSign,
            ApprovalFormatStyle: d.ApprovalFormatStyle || "1"
          };
          var f = r.findIndex(function (e) {
            return e.Expression === d.Expression
          });
          -1 === f ? (delete d.RootMetaDataID,
            r.push(d)) : f >= 0 && (delete d.RootMetaDataID,
              r.splice(f, 1),
              r.push(d))
        } else if ("[object Object]" === Object.prototype.toString.call(d) && d.hasOwnProperty("qrCode")) {
          copyQr[n + ":" + u] = {
            contentType: d.contentType,
            content: d.content,
          }
        } else if ("[object Object]" === Object.prototype.toString.call(d) && d.hasOwnProperty("brCode")) {
          copyBr[n + ":" + u] = {
            codeType: d.codeType,
            contentType: d.contentType,
            content: d.content,
          }
        } else {
          "[object Object]" === Object.prototype.toString.call(d) && d.hasOwnProperty("ClientUrl") ? c[n + ":" + u] = {
            FileName: d.FileName,
            MediaType: d.MediaType,
            DfsPath: d.DfsPath,
            ClientUrl: d.ClientUrl,
            Content: d.Content,
            MetaFieldName: d.MetaFieldName,
            IsDigSign: d.IsDigSign
          } : "[object Object]" === Object.prototype.toString.call(d) && d.fromCopy ? (a[n + ":" + u] = a[d.row + ":" + d.col],
            c[n + ":" + u] = c[d.row + ":" + d.col]) : s.push(t);
          i.push([n, u, e.hotInstance.getDataAtCell(n, u)])
        }
      }),
        this.diffObject = {
          presentCellFieldMap: n,
          updatedCellFieldMap: a,
          presentCellImgMap: u,
          updatedCellImgMap: c,
          presentCellQRcodeMap: cellWithQRcode,
          updatedCellQRcodeMap: copyQr,
          presentCellBRcodeMap: cellWithBRcode,
          updatedCellBRcodeMap: copyBr,
          presentCellData: i,
          updatedCellData: s,
          presentFilter: o,
          updatedFilter: l
        },
        this
    }
  }
  applyChange() {
    return this.hotInstance.setDataAtCell(this.diffObject.updatedCellData),
      this.hotInstance.updateSettings({
        cellWithField: this.diffObject.updatedCellFieldMap,
        filters: this.diffObject.updatedFilter,
        cellWithImg: this.diffObject.updatedCellImgMap,
        cellWithQRcode: this.diffObject.updatedCellQRcodeMap,
        cellWithBRcode: this.diffObject.updatedCellBRcodeMap,
      }),
      this
  }
  revertChange() {
    return this.hotInstance.setDataAtCell(this.diffObject.presentCellData),
      this.hotInstance.updateSettings({
        cellWithField: this.diffObject.presentCellFieldMap,
        filters: this.diffObject.presentFilter,
        cellWithImg: this.diffObject.presentCellImgMap,
        cellWithQRcode: this.diffObject.presentCellQRcodeMap,
        cellWithBRcode: this.diffObject.presentCellBRcodeMap,
      }),
      this
  }
}

export class ne {
  constructor(t, n) {
    this.cellFields = t
    this.hotInstance = n
    this.diffObject = {}
  }

  diff() {
    var e, t = this.hotInstance.getSettings(), n = t.cellWithField, o = t.filters, r = Object.assign({}, n);
    this.cellFields && Array.isArray(this.cellFields) && this.cellFields.length > 0 ? this.cellFields[0].hasOwnProperty("key") && this.cellFields[0].hasOwnProperty("val") && this.cellFields.forEach(function (e) {
      r[e.key] = e.val
    }) : this.cellFields && (r = this.cellFields);
    var i = Object.values(r) && Object.values(r).map(function (e) {
      return e.RootMetaDataID
    });
    return e = o.filter(function (e) {
      return i.indexOf(e.metaDataID) > -1
    }),
      this.diffObject = {
        presentCellFieldMap: n,
        updatedCellFieldMap: r,
        presentFilters: o,
        updatedFilters: e
      },
      this
  }
  applyChange(e) {
    return this.hotInstance.updateSettings({
      cellWithField: this.diffObject.updatedCellFieldMap,
      filters: this.diffObject.updatedFilters
    }),
      this
  }
  revertChange(e) {
    return this.hotInstance.updateSettings({
      cellWithField: this.diffObject.presentCellFieldMap,
      filters: this.diffObject.presentFilters
    }),
      this
  }
}
export class qr {
  constructor(t, n) {
    this.cellWithQRcode = t
    this.hotInstance = n
    this.diffObject = {}
  }
  diff() {
    var e = this.hotInstance.getSettings().cellWithQRcode
      , t = Object.assign({}, e);
    this.cellWithQRcode && Array.isArray(this.cellWithQRcode) && this.cellWithQRcode.length > 0 ? this.cellWithQRcode[0].hasOwnProperty("key") && this.cellWithQRcode[0].hasOwnProperty("val") && this.cellWithQRcode.forEach(function (e) {
      t[e.key] = e.val
    }) : this.cellWithQRcode && (t = this.cellWithQRcode);
    return this.diffObject = {
      presentCellQRcodeMap: e,
      updatedCellQRcodeMap: t
    },
      this
  }
  applyChange(e) {
    return this.hotInstance.updateSettings({
      cellWithQRcode: this.diffObject.updatedCellQRcodeMap
    }),
      this
  }
  revertChange(e) {
    return this.hotInstance.updateSettings({
      cellWithQRcode: this.diffObject.presentCellQRcodeMap
    }),
      this
  }
}
export class br {
  constructor(t, n) {
    this.cellWithBRcode = t
    this.hotInstance = n
    this.diffObject = {}
  }
  diff() {
    var e = this.hotInstance.getSettings().cellWithBRcode
      , t = Object.assign({}, e);
    this.cellWithBRcode && Array.isArray(this.cellWithBRcode) && this.cellWithBRcode.length > 0 ? this.cellWithBRcode[0].hasOwnProperty("key") && this.cellWithBRcode[0].hasOwnProperty("val") && this.cellWithBRcode.forEach(function (e) {
      t[e.key] = e.val
    }) : this.cellWithBRcode && (t = this.cellWithBRcode);
    return this.diffObject = {
      presentCellBRcodeMap: e,
      updatedCellBRcodeMap: t
    },
      this
  }
  applyChange(e) {
    return this.hotInstance.updateSettings({
      cellWithBRcode: this.diffObject.updatedCellBRcodeMap
    }),
      this
  }
  revertChange(e) {
    return this.hotInstance.updateSettings({
      cellWithBRcode: this.diffObject.presentCellBRcodeMap
    }),
      this
  }
}

export class X {
  constructor(t, n) {
    this.cellImgs = t
    this.hotInstance = n
    this.diffObject = {}
  }

  diff() {
    var e = this.hotInstance.getSettings().cellWithImg
      , t = Object.assign({}, e);
    this.cellImgs && Array.isArray(this.cellImgs) && this.cellImgs.length > 0 ? this.cellImgs[0].hasOwnProperty("key") && this.cellImgs[0].hasOwnProperty("val") && this.cellImgs.forEach(function (e) {
      t[e.key] = e.val
    }) : this.cellImgs && (t = this.cellImgs);
    Object.values(t) && Object.values(t).map(function (e) {
      return e.RootMetaDataID
    });
    return this.diffObject = {
      presentCellImgMap: e,
      updatedCellImgMap: t
    },
      this
  }
  applyChange(e) {
    return this.hotInstance.updateSettings({
      cellWithImg: this.diffObject.updatedCellImgMap
    }),
      this
  }
  revertChange(e) {
    return this.hotInstance.updateSettings({
      cellWithImg: this.diffObject.presentCellImgMap
    }),
      this
  }
}

export class oe {
  constructor(t, n) {
    this.tableStructure = t
    this.hotInstance = n
    this.diffObject = {}
  }

  diff() {
    var e = this.hotInstance.getSettings()
      , t = e.colws || []
      , n = e.rowhs || [];
    if (this.tableStructure.colws)
      if ("[object Object]" === Object.prototype.toString.call(this.tableStructure.colws))
        this.diffObject.preColws = t,
          this.diffObject.updateColws = "create" === this.tableStructure.colws.op ? [].concat(J(t.slice(0, this.tableStructure.colws.index)), J(new Array(this.tableStructure.colws.amount)), J(t.slice(this.tableStructure.colws.index))) : [].concat(J(t.slice(0, this.tableStructure.colws.index)), J(t.slice(this.tableStructure.colws.index + this.tableStructure.colws.amount)));
      else {
        this.diffObject.preColws = [];
        for (var o = 0; o < this.tableStructure.colws.length; o++) {
          var r = this.tableStructure.colws[o].columnIndex;
          this.diffObject.preColws.push({
            columnIndex: r,
            width: t[r] === undefined ? e.defaultColWidth : t[r]
          })
        }
        this.diffObject.updateColws = this.tableStructure.colws
      }
    if (this.tableStructure.rowhs)
      if ("[object Object]" === Object.prototype.toString.call(this.tableStructure.rowhs))
        this.diffObject.preRowhs = n,
          this.diffObject.updateRowhs = "create" === this.tableStructure.rowhs.op ? [].concat(J(n.slice(0, this.tableStructure.rowhs.index)), J(new Array(this.tableStructure.rowhs.amount)), J(n.slice(this.tableStructure.rowhs.index))) : [].concat(J(n.slice(0, this.tableStructure.rowhs.index)), J(n.slice(this.tableStructure.rowhs.index + this.tableStructure.rowhs.amount)));
      else {
        this.diffObject.preRowhs = [];
        for (var i = 0; i < this.tableStructure.rowhs.length; i++) {
          var a = this.tableStructure.rowhs[i].rowIndex;
          this.diffObject.preRowhs.push({
            rowIndex: a,
            height: n[a] === undefined ? e.defaultRowHeight : n[a]
          })
        }
        this.diffObject.updateRowhs = this.tableStructure.rowhs
      }
    return this
  }
  applyChange() {
    var e = this.hotInstance.getSettings()
      , t = e.colws
      , n = e.rowhs;
    this.diffObject.updateColws && ("[object Object]" === Object.prototype.toString.call(this.tableStructure.colws) ? t = this.diffObject.updateColws : this.diffObject.updateColws.forEach(function (e) {
      t[e.columnIndex] = e.width
    }))
    this.diffObject.updateRowhs && ("[object Object]" === Object.prototype.toString.call(this.tableStructure.rowhs) ? n = this.diffObject.updateRowhs : this.diffObject.updateRowhs.forEach(function (e) {
      n[e.rowIndex] = e.height
    }))
    this.hotInstance.getSettings().colws = t
    this.hotInstance.getSettings().rowhs = n
    console.log(t, n);
    this.hotInstance.updateSettings({
      manualColumnResize: !1,
      manualRowResize: !1,
      rowhs: n,
      colws: t
    })
    this.hotInstance.updateSettings({
      manualColumnResize: !0,
      manualRowResize: !0
    })
    return this
  }
  revertChange() {
    var e = this.hotInstance.getSettings()
      , t = e.colws
      , n = e.rowhs;
    this.diffObject.preColws && ("[object Object]" === Object.prototype.toString.call(this.tableStructure.colws) ? e.colws = this.diffObject.preColws : this.diffObject.preColws.forEach(function (e) {
      t[e.columnIndex] = e.width
    }))
    this.diffObject.preRowhs && ("[object Object]" === Object.prototype.toString.call(this.tableStructure.rowhs) ? e.rowhs = this.diffObject.preRowhs : this.diffObject.preRowhs.forEach(function (e) {
      n[e.rowIndex] = e.height
    }))
    this.hotInstance.getSettings().colws = t
    this.hotInstance.getSettings().rowhs = n
    console.log(t, n, 'revertChange');
    this.hotInstance.updateSettings({
      manualColumnResize: !1,
      manualRowResize: !1,
      rowhs: n,
      colws: t
    })
    this.hotInstance.updateSettings({
      manualColumnResize: !0,
      manualRowResize: !0
    })
    return this
  }
}